package com.take.state;

import java.util.HashMap;
import java.util.Map;

public class OrderStateMachine {

    public static final Map<OrderStateEnum, OrderState> ORDER_STATE_MAP = new HashMap<>();

    static {
        ORDER_STATE_MAP.put(OrderStateEnum.WAIT_PAYMENT, new WaitPaymentState());
        ORDER_STATE_MAP.put(OrderStateEnum.WAIT_DELIVER, new WaitDeliverState());
        ORDER_STATE_MAP.put(OrderStateEnum.WAIT_RECEIVE, new WaitReceiveState());
        ORDER_STATE_MAP.put(OrderStateEnum.RECEIVED, new ReceivedState());
        ORDER_STATE_MAP.put(OrderStateEnum.CANCEL, new CancelState());
    }

    private OrderState currentState;

    public OrderStateMachine(OrderStateEnum orderStateEnum) {
        this.currentState = ORDER_STATE_MAP.get(orderStateEnum);
    }

    public OrderState getCurrentState() {
        return currentState;
    }

    public void setCurrentState(OrderState currentState) {
        this.currentState = currentState;
    }

    public void pay() {
        currentState.pay(this);
    }

    public void deliver() {
        currentState.deliver(this);
    }

    public void receive() {
        currentState.receive(this);
    }

    public void cancel() {
        currentState.cancel(this);
    }

}
